<?php
namespace app\api\controller\wdsxh;
use addons\wdsxh\library\Wxapp;
/**
 * 海报接口
 */
class Poster extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    /*
     * 公司海报
     */
    public function unit(){
        if(!$this->request->isPost()) {
            $this->error('请求类型错误');
        }

        $id=$this->request->param('id',0);
        if(empty($id)){
            $this->error('id参数错误');
        }
        $data=\app\admin\model\wdsxh\MemberUnit::get($id);
        if(!$data){
            $this->error('会员信息不存在');
        }
//        $images=explode(',',$data->company_images);
//        $images[0] = str_replace($this->request->domain(),'',$images[0]);
//        $banner=ROOT_PATH.'public'.$images[0];
        $banner=ROOT_PATH.'public/static/company_poster.png';
        $qrcode=Wxapp::getQrcode('/pages/Component/Module/Main/Program/company/index/index?id='.$id.'&uid='.$this->auth->id);
        $user=$this->auth->getUserinfo();
        $res=\addons\wdsxh\library\Posters::create(1,$qrcode,$user['avatar'],$user['nickname'],$banner,$data->company_name);
        if($res && is_array($res)){
            $this->success('success',$res['url']);
        }else{
            $this->error('创建海报失败');
        }
    }
    /*
     * 活动海报
     */
    public function activity(){
        if(!$this->request->isPost()) {
            $this->error('请求类型错误');
        }

        $id=$this->request->param('id',0);
        if(empty($id)){
            $this->error('id参数错误');
        }
        $data= \app\admin\model\wdsxh\Activity::get($id);
        if(!$data){
            $this->error('活动信息不存在');
        }
        $images=explode(',',$data->images);
        $images[0] = str_replace($this->request->domain(),'',$images[0]);
        $banner=ROOT_PATH.'public'.$images[0];
        $qrcode=Wxapp::getQrcode('/pages/Component/Module/Main/Program/activity/detail/index?id='.$id.'&uid='.$this->auth->id);
        $user=$this->auth->getUserinfo();
        $res=\addons\wdsxh\library\Posters::create(2,$qrcode,$user['avatar'],$user['nickname'],$banner,$data->title);
        if($res && is_array($res)){
            $this->success('success',$res['url']);
        }else{
            $this->error('创建海报失败');
        }
    }

    /*
     * 商圈海报
     */
    public function business(){
        if(!$this->request->isPost()) {
            $this->error('请求类型错误');
        }

        $id=$this->request->param('id',0);
        if(empty($id)){
            $this->error('id参数错误');
        }
        $data= \app\admin\model\wdsxh\Business::get($id);
        if(!$data){
            $this->error('商圈信息不存在');
        }
        $images=explode(',',$data->image);
        $images[0] = str_replace($this->request->domain(),'',$images[0]);
        $banner=ROOT_PATH.'public'.$images[0];
        $qrcode=Wxapp::getQrcode('/pages/Component/Module/Circle/Program/detail/index?id='.$id.'&uid='.$this->auth->id);
        $user=$this->auth->getUserinfo();
        $res=\addons\wdsxh\library\Posters::create(3,$qrcode,$user['avatar'],$user['nickname'],$banner,$data->title);
        if($res && is_array($res)){
            $this->success('success',$res['url']);
        }else{
            $this->error('创建海报失败');
        }
    }

}